package com.cp.admin.modular.user.controller;

import com.cp.admin.modular.user.model.UserFriendInfo;
import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.user.service.IUserFriendInfoService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2020-08-26 09:50:17
 */
@Controller
@RequestMapping("/userFriendInfo")
public class UserFriendInfoController extends BaseController {

    private String PREFIX = "/user/userFriendInfo/";

    @Autowired
    private IUserFriendInfoService userFriendInfoService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "userFriendInfo.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/userFriendInfo_add")
    public String userFriendInfoAdd() {
        return PREFIX + "userFriendInfo_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/userFriendInfo_update/{userFriendInfoId}")
    public String userFriendInfoUpdate(@PathVariable Long userFriendInfoId, Model model) {
        UserFriendInfo userFriendInfo = userFriendInfoService.selectById(userFriendInfoId);
        model.addAttribute("item",userFriendInfo);
        LogObjectHolder.me().set(userFriendInfo);
        return PREFIX + "userFriendInfo_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return userFriendInfoService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UserFriendInfo userFriendInfo) {
        userFriendInfoService.insert(userFriendInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long userFriendInfoId) {
        userFriendInfoService.deleteById(userFriendInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UserFriendInfo userFriendInfo) {
        userFriendInfoService.updateById(userFriendInfo);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{userFriendInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("userFriendInfoId") Long userFriendInfoId) {
        return userFriendInfoService.selectById(userFriendInfoId);
    }
}
